package cn.itsource.shiro.realm;

import cn.itsource.crm.domain.Permission;
import cn.itsource.crm.service.IPermissionService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

/**
 * @author xjh
 * @date 2020/3/31 0:45
 */
public class FilterChainDefinitionMapBuilder {

    @Autowired
    private IPermissionService permissionService;
    public Map<String,String> createFilterChainDefinitionMap(){
        Map<String, String> map = new LinkedHashMap();
        //静态资源放行
        map.put("*.js","anon");
        map.put("*.css","anon");
        map.put("/css/**","anon");
        map.put("/js/**","anon");
        map.put("/easyui/**","anon");
        map.put("/images/**","anon");
        map.put("/resources/**","anon");

        /*特殊url放行*/
        map.put("/callback","anon");
        map.put("/login","anon");
        map.put("/bind","anon");
        map.put("/file/logoUpload","anon");
        map.put("/tenant/save","anon");
        map.put("/employee/save","anon");
        map.put("/department/list/*","anon");
        map.put("/tenant/queryByName","anon");

        /*权限拦截*/
        List<Permission> permissions = permissionService.findAll();
        for (Permission permission : permissions) {
            String url = permission.getUrl();
            String sn = permission.getSn();
            map.put(url, "MyPerm["+sn+"]");
        }

        /*拦截非特殊放行的url,判断是否已认证用户 */
        map.put("/**","myAuthc");
        return  map;
    }
}